﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

using XGameFrame;
using XGameFrame.Controls;
using XTowerDef.GameScreens.TitleScreenElements;

namespace XTowerDef.GameScreens
{
    public class TitleScreen:BaseGameState
    {
        #region Field region

        Texture2D backgroundImage;
        LinkLabel startLabel;
        MouseSprite mouseSprite;

        #endregion

        #region Constructor region

        public TitleScreen(Game game, GameStateManager manager)
            : base(game, manager)
        {

        }

        #endregion

        #region XNA Method region

        protected override void LoadContent()
        {
            ContentManager Content = GameRef.Content;

            base.LoadContent();

            backgroundImage = Content.Load<Texture2D>(@"Backgrounds\titlescreen");
            startLabel = new LinkLabel(new Vector2(50f, 200f),
                "Press ENTER to begin");
            startLabel.Color = Color.White;
            startLabel.Selected += new SelectedControls(startLabel_Selected);
            ControlManager.Add(startLabel);

            //new testing loading mouse
            Texture2D mouseGraphic = Content.Load<Texture2D>(@"GameGraphics\Mouse\glowing-cursor2");
            mouseSprite = new MouseSprite(mouseGraphic, InputHandler.CurrentMousePosition);
            mouseSprite.Scale = 0.2f;
            StaticSpriteManager.Add(mouseSprite);

        }

        public override void Update(GameTime gameTime)
        {
            ControlManager.Update(gameTime, PlayerIndex.One);
            StaticSpriteManager.Update(gameTime, PlayerIndex.One);
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            GameRef.SpriteBatch.Begin();
            base.Draw(gameTime);
            GameRef.SpriteBatch.Draw(
                    backgroundImage,
                    GameRef.ScreenRectangle,
                    Color.White);
            ControlManager.Draw(GameRef.SpriteBatch);
            StaticSpriteManager.Draw(GameRef.SpriteBatch);
            GameRef.SpriteBatch.End();
        }

        #endregion

        #region Title Screen Methods

        private void startLabel_Selected(object sender, EventArgs e)
        {
            StateManager.PushState(GameRef.StartMenuScreen);
        }
        #endregion
    }
}
